﻿pragma Singleton
import QtQuick
import FilUI

Item {
    id: control

    property var tlist: []

    function readRecord(objname) {
        for (var i = 0; i < tlist.length; i++) {
            if (objname === tlist[i]) {
                console.log("readRecord found tour record:", objname)
                return true
            }
        }
        return false
    }

    function addRecord(objname) {
        console.log("addRecord", objname)
        tlist.push(objname)
        SettingsHelper.saveAppTour(JSON.stringify(tlist))
    }

    function removeRecord(objname) {
        console.log("removeRecord", objname)
        tlist.filter(item => item !== objname)
    }

    function clearAll() {
        console.log("clearAll")
        SettingsHelper.saveAppTour("")
    }

    Component.onCompleted: {
        var recordValue = SettingsHelper.getAppTour()
        if (recordValue.length > 0) {
            var json = JSON.parse(recordValue)
            if (json && json.length > 0) {
                console.log("load tour data:", JSON.stringify(json))
                for (var i = 0; i < json.length; i++) {
                    tlist.push(json[i])
                }
            }
        }
    }
}
